﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Slaks.Graphs.Analysis.CategorizationMeasures
{
    public class Accuracy : CategorizationMeasureBase
    {
        public override object evaluate(Dictionary<Graph, string> resultsSet, Slaks.Graphs.Category.CategoriesFile categoriesFile)
        {
            var correct = 0d;
            var retrieved = new Dictionary<string, IList<Graph>>();
            foreach (KeyValuePair<Graph, string> pair in resultsSet)
            {
                Graph graph = pair.Key;
                string category = pair.Value;
                if (graph.Category == category)
                {
                    correct++;
                }
                if (!retrieved.ContainsKey(category))
                {
                    retrieved[category] = new List<Graph>();
                }
                retrieved[category].Add(graph);
            }
            return correct * 1.0 / resultsSet.Count;
        }

        public override string getMeasureName()
        {
            return "Accuracy";   
        }
    }
}
